import { Graph } from 'graphlib';
import { Chunk } from './chunk';

export class ChunkGraph {
  graph: Graph;

  constructor() {
    this.graph = new Graph();
  }

  getChunk(id: string): Chunk {
    return this.graph.node(id);
  }

  hasChunk(id: string) {
    return !!this.graph.hasNode(id);
  }

  addChunk(chunk: Chunk) {
    return this.graph.setNode(chunk.id, chunk);
  }

  getChunks() {
    return this.graph.nodes();
  }
}
